﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:v="http://d3works.com/xml/ns/object-views"
>
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>视图文档</title>
        <link rel="stylesheet" href="../../../../../schemas/github.css"/>
      </head>
      <body>
        <div id="write">
          <xsl:call-template name="tpl-action-menu"/>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="tpl-action-menu">
    <h1>菜单</h1>
    <table cellpadding="2" cellspacing="1">
      <thead>
        <tr>
          <th>名称</th>
          <th>标题</th>
          <th>上级菜单</th>
          <th>动作</th>
        </tr>
      </thead>
      <tbody>
        <xsl:for-each select="/v:object-views/v:action-menu">
          <tr>
            <td>
              <xsl:value-of select="@name"/>
            </td>
            <td>
              <xsl:value-of select="@title"/>
            </td>
            <td>
              <xsl:value-of select="@parent"/>
            </td>
            <td>
              <xsl:choose>
                <xsl:when test="@action != ''">
                  <xsl:call-template name="tpl-action-view">
                    <xsl:with-param name="name" select="@action"/>
                  </xsl:call-template>
                </xsl:when>
              </xsl:choose>
            </td>
          </tr>
        </xsl:for-each>
      </tbody>
    </table>

  </xsl:template>
  <xsl:template name="tpl-action-view">
    <xsl:param name="name" />
    <xsl:variable name="node" select="/v:object-views/v:action-view[@name = $name]"/>
    <p>
      [<strong>
        <xsl:value-of select="$node/@title"/>
      </strong>]:
      <i>
        <xsl:value-of select="$name"/>
      </i>
    </p>
    <dl>
      <xsl:for-each select="$node/v:view">
        <dd>
          <strong>
            <xsl:value-of select="@type"/>:
            <a>
              <xsl:attribute name="href">#<xsl:value-of select="@name"/></xsl:attribute>
              <xsl:value-of select="@name"/>
            </a>
          </strong> 
        </dd>
      </xsl:for-each>
    </dl>
    
  </xsl:template>
</xsl:stylesheet>
